load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc", "rust_doc_test")

# Build binary
rust_binary(
    name = "bin",
    srcs = glob([
        "src/*/*.rs",
        "src/*.rs",
    ]),
    crate_root = "src/main.rs",
    rustc_flags = select({
        "//:release": [
            "-Clink-arg=-flto",
            "-Ccodegen-units=1",
            "-Cpanic=abort",
            "-Copt-level=3",
            "-Cstrip=symbols",
        ],
        "//conditions:default": [
            "-Copt-level=0",
        ],
    }),
    tags = [
        "rest-tokio",
        "service",
    ],
    visibility = ["//visibility:public"],
    deps = [
        # External crates
        "@crates//:arc-swap",
        "@crates//:serde",
        "@crates//:serde_json",
        "@crates//:tokio",
        "@crates//:tokio-cron-scheduler",
        "@crates//:warp",
    ],
)

# Build documentation
rust_doc(
    name = "doc",
    crate = ":bin",
    tags = ["doc"],
    visibility = ["//visibility:public"],
)

# Test documentation
rust_doc_test(
    name = "doc_test",
    crate = ":bin",
    tags = ["doc-test"],
    visibility = ["//visibility:public"],
)
